
function scroll_top() {
	var timer = null;
	var s = document.querySelector(".scroll");
	window.onscroll = function(event) {
		if(document.documentElement.scrollTop > 2000) {
			s.className = "scroll d-b";
		}else if(document.documentElement.scrollTop < 300){
			s.className = "scroll d-n";
		}
	}
	var s_top = document.getElementById("scroll_top");
	s_top.onclick = function (){
		animate(document.documentElement.scrollTop,0,1000);
	}

	
}

function animate(obj,target,time,callback){
//		frame是帧数
		var frame = 20;
//		totalFrame是时间除以进度,获得总共多少次
		var totalFrame = time/frame;
//		t用来判定完成,清除定时器
		var t = 0;
//		change用来每次走多少
		var change = obj / totalFrame;
		var obj_top = obj - target > 0 ? -change : change;
		timer = setInterval(function(){
			obj += obj_top;
			document.documentElement.scrollTop = obj;
			t++;
			if(t>=totalFrame){
				callback && callback();
				clearInterval(timer);
			}
		},frame);
}
//	头部下拉/	头部下拉
	function top_slider(){
		//	top_right start
		//	点击按钮实现下来菜单
		var index = 0;
		var top_right = document.getElementById("top_right");
		var btn = top_right.getElementsByTagName("button");
		var top_silder = top_right.getElementsByTagName("span");
		var slider_li = top_right.getElementsByClassName("slider-li");
		for(var i = 0; i < btn.length; i++) {
			btn[i].index = i;
			btn[i].onclick = function() {
				top_silder[this.index].className = "transtion";
			}
		}
		for(var i = 0; i < slider_li.length; i++) {
			slider_li[i].index = i;
			slider_li[i].onmouseleave = function() {
				top_silder[this.index].className = "close";
			}
		}
	//	top_right end
	}
	
	//导航栏跟随
	function search_flex(){
		var search = document.getElementsByClassName("search")[0];
		
		window.addEventListener("scroll",function(){
			if(document.documentElement.scrollTop > (search.offsetTop + search.offsetHeight)){
				search.style.position = "fixed";
				search.style.top = "-28px";
				search.style.right = "190px";

			}else if(document.documentElement.scrollTop < 60){
				search.style.position = "relative";
				search.style.top = "0px";
				search.style.right = "0px";
			}
		})
	}
//	本地储存 start
	var flag = true;
	function set_localStorage(obj){
		var user_arr = [];
		//设置之前先判断是否存在数据
		var user_infos = get_localStorage('user_info');
		if(!user_infos){
			user_arr.push(obj);
			localStorage.setItem("user_info",JSON.stringify(user_arr));
		}else {
			flag = true;
			for(var i = 0; i < user_infos.length; i++){
				if(user_infos[i].user === obj.user){
					flag = false;
					alert("用户已经存在！请登录");
					break;
				}
			}
			if(flag){
				user_infos.push(obj);
				localStorage.setItem("user_info",JSON.stringify(user_infos));
				return flag;
			}
		}
	}
//	function setItems(uName,user_arr){
//		localStorage.setItem(uName,JSON.stringify(user_arr));
//	}
	function get_localStorage(name){
		//获取本地储存
		var users = localStorage.getItem(name);
		//解析
		var user_info = JSON.parse(users);
//		返回解析的json
		return user_info;
	}

//	本地储存 end

//	加减操作
	function add(v){
		var num = parseInt(v.value);
		num++;
		if(num > 99){
			num = 99;
		}
		v.value = num;
	}
	function reduce(v){
		var num = parseInt(v.value);
		num--;
		if(num < 0){
			num = 0;
		}
		v.value = num;
	}
	
	function sale(){
		var cook = get_localStorage("user_info");
		var flag = true;
		var login = document.getElementById("login");
		var reister = document.getElementById("reister");
		var img_t = document.getElementById("img_t");
		var out = document.getElementById("out");
		var login_html = document.getElementById("login_html");
		var shop_C = document.getElementById("shop_C");
		var scj = document.getElementById("scj");
		if(cook && flag){
			login.className = "d-n";
			reister.className = "d-n";
			img_t.className = "d-b";
			out.className = "d-b";
			login_html.href = "order.html";
			shop_C.href = "shop_car.html";
			scj.href = "#";
		}
		out.onclick = function(){
			login.className = "d-b";
			reister.className = "red-color d-b";
			img_t.className = "d-n";
			out.className = "d-n";
			login_html.href = "login.html";
			shop_C.href = "login.html";
			scj.href = "login.html";
			flag = false;
			localStorage.clear();
		}
	}










//设置本地储存
	function set(obj){
//		先获取看本地是否有数据
		var pro_obj = get('pro_info');
		var arr = [];
		//如果不存在
		if(!pro_obj){
			//添加进去
			arr.push(obj);
			setLocalstorage('pro_info', arr);
		}else {
			var flag = true;
			for(var i = 0; i < pro_obj.length; i++){
				if(pro_obj[i].id == obj.id){
					pro_obj[i].pro_num = parseInt(pro_obj[i].pro_num);
					pro_obj[i].pro_num += 1;
					setLocalstorage('pro_info', pro_obj);
					flag = false;
					break;
				}
			}
			if(flag){
				pro_obj.push(obj);
				setLocalstorage('pro_info', pro_obj);
			}
		}
	}
	
	function setLocalstorage(pro_name, pro_arr){
		localStorage.setItem(pro_name,JSON.stringify(pro_arr));
	}
//	获取本地存储
	function get(pro_name){
		var pro_info = localStorage.getItem(pro_name);
		var pro_infos = JSON.parse(pro_info);
		return pro_infos;
	}
	

